<template>
  <!-- 评委评审 -->
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="团队名称" prop="college">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入团队名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指导单位" prop="college">
        <el-select v-model="queryParams.college" placeholder="请选择" clearable size="small">
          <el-option
            v-for="(dict, index) in unitNameList"
            :key="index"
            :label="dict.sponsorName"
            :value="dict.sponsorName"
          />
        </el-select>
        <!-- <el-input
          v-model="queryParams.college"
          placeholder="请输入指导单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        /> -->
      </el-form-item>
      <el-form-item label="调研主题" prop="researchtopic">
        <el-select
          v-model="queryParams.researchtopic"
          placeholder="调研主题"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="(dict, index) in researchtopics"
            :key="index"
            :label="dict.optionName"
            :value="dict.optionId"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="推荐项" prop="researchtopic">
        <el-select
          v-model="queryParams.researchtopic"
          placeholder="推荐项"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in recommendOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <span style="font-weight: bold">校园大赛</span>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleExport"
          v-hasPermi="['eqxm:schoolmatchScore:export']"
          >导出评审表</el-button
        >
        <!-- <el-button type="info" plain size="mini" @click="handleImport">导入线下评分</el-button> -->
        <el-button
          type="info"
          plain
          size="mini"
          @click="handleImportOnline"
          v-hasPermi="['eqxm:schoolmatchScore:ImportOnline']"
          >导入线上评分</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="toPsOpen"
          v-hasPermi="['eqxm:schoolmatchScore:ps']"
          >评分评审</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handlePF"
          v-hasPermi="['eqxm:schoolmatchScore:pf']"
          >评分</el-button
        >
      </el-col>

      <!-- <el-col :span="1.5">
		  <el-button
		    type="primary"
		    plain
		    size="mini"
		    @click="handleExport"
		    v-hasPermi="['eqxm:team:export']"
		  >导入线上评分</el-button>
		</el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="recommendTeam"
          v-hasPermi="['eqxm:team:add']"
        >推荐团队</el-button>
      </el-col>
     <el-col :span="1.5">
       <el-button
         type="primary"
         plain
         size="mini"
         @click="judge"
         v-hasPermi="['eqxm:team:add']"
       >评委任命</el-button>
     </el-col>
     <el-col :span="1.5">
       <el-button
         type="primary"
         plain
         size="mini"
         @click="review"
         v-hasPermi="['eqxm:team:add']"
		 v-if="isHaveReviewRole"
       >评审</el-button>
     </el-col>
     <el-col :span="1.5">
       <el-button
         type="primary"
         plain
         size="mini"
         @click="review"
         v-hasPermi="['eqxm:team:add']"
       >导入线下评分</el-button>
     </el-col>
     <el-col :span="1.5">
       <el-button
         type="primary"
         plain
         size="mini"
         @click="collegeScore1"
         v-hasPermi="['eqxm:team:add']"
       >录入系部评审成绩</el-button>
     </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="teamList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column label="团队名称" align="center" prop="name" />
      <el-table-column label="负责人" align="center">
        <template slot-scope="scope">
          <div
            style="border-bottom: 1px solid #ddd"
            v-for="(val, index) in scope.row.eqxmTeamStudentList"
            :key="index"
            v-if="val.role == '1'"
          >
            <div>{{ val.name }}-{{ val.username + '\n' }}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="指导单位" align="center" prop="college" />
      <el-table-column label="调研主题" align="center" prop="researchtopic" />
      <!-- <el-table-column label="实打/应打" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <span>{{ scope.row.clockCount }}/{{ scope.row.studentCount }}</span>
          <br />
          <span>{{ GetPercent(scope.row.clockCount, scope.row.studentCount) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="系部评分" align="center" prop="collegeScore1" />

      <el-table-column label="系部排名" align="center" prop="rank">
        <template slot-scope="scope">
          <span>{{ scope.row.rank }}/{{ scope.row.rankCount }}</span>
        :formatter="getClockScore"
        </template>
      </el-table-column> -->
      <el-table-column label="打卡得分" align="center" prop="clockScore" />
      <el-table-column label="团队材料" align="center" prop="college">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            v-hasPermi="['eqxm:schoolmatchScore:teamDetail']"
            @click="handleUpdate(scope.row)"
            >团队信息</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="seeUpload(scope.row, '3')"
            v-hasPermi="['eqxm:schoolmatchScore:sumDetail']"
            >宣传材料</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="总结材料" align="center" prop="college">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-download"
            @click="openUrl(scope.row.id)"
            v-hasPermi="['eqxm:schoolmatchScore:sumDetail']"
            >材料</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="onlineStatus1">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.schoolmatch_2" :value="scope.row.onlineStatus1" />
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="打卡得分"
        :formatter="getClockScore"
        align="center"
        prop="actualClockAllCount"
      />
      <el-table-column label="线上评分" align="center" prop="onlineScore1" />
      <el-table-column label="线下评分" align="center" prop="offlineScore" />
      <el-table-column label="总分" align="center" prop="totalScore1" :formatter="getAllScore" />
      <el-table-column label="获得奖项" align="center" prop="teamPrize1" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="schoolMatchPrizeOpenF(scope.row)"
            >颁奖</el-button
          >
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改团队对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="系部" prop="college">
          <el-input v-model="form.college" placeholder="请输入系部" />
        </el-form-item>
        <el-form-item label="调研主题" prop="researchtopic">
          <el-input v-model="form.researchtopic" placeholder="请输入调研主题" />
        </el-form-item>
        <el-form-item label="是否重点" prop="isimportant">
          <el-input v-model="form.isimportant" placeholder="请输入是否重点" />
        </el-form-item>
        <el-form-item label="呈现形式" prop="presentation">
          <el-input v-model="form.presentation" placeholder="请输入呈现形式" />
        </el-form-item>
        <el-form-item label="呈现形式详情" prop="presentationdetail">
          <el-input v-model="form.presentationdetail" placeholder="请输入呈现形式详情" />
        </el-form-item>
        <el-form-item label="交通费" prop="transportation">
          <el-input v-model="form.transportation" placeholder="请输入交通费" />
        </el-form-item>
        <el-form-item label="住宿费" prop="accommodation">
          <el-input v-model="form.accommodation" placeholder="请输入住宿费" />
        </el-form-item>
        <el-form-item label="宣传费" prop="publicity">
          <el-input v-model="form.publicity" placeholder="请输入宣传费" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 颁奖对话框 -->
    <el-dialog title="颁奖" :visible.sync="advancedPrizeOpen" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="奖项名称" prop="advancedPrize">
          <el-input v-model="advancedPrize" placeholder="请输入奖项名称" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="advancedPrizeSubmitForm">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport + '&scoreType=1'"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <!--    <div class="el-upload__tip" slot="tip">
	      <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
	    </div> -->
        <div class="el-upload__tip" style="color: red" slot="tip">
          提示：仅允许导入xlsx格式文件！
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="评分评审" :visible.sync="psOpen" width="500px" append-to-body>
      角色：
      <el-select
        @change="collegeAccreditation(judgeId)"
        v-model="judgeId"
        placeholder="请选择"
        clearable
        size="small"
        prop="judgeId"
      >
        <el-option
          v-for="(dict, index) in judgeList"
          :key="index"
          :label="dict.nickName + '-' + dict.userName"
          :value="dict.userName"
        />
      </el-select>
      <!-- <el-select
                  :remote-method="searchUser"
                  filterable
                  remote
                >
                </el-select> -->
      <el-table
        style="margin-top: 10px"
        border
        :data="psList"
        @selection-change="handleSelectionChangePs"
      >
        <!-- <el-table-column type="selection" width="50" align="center" /> -->
        <el-table-column label="评审老师" align="center" prop="updateBy" />
        <el-table-column label="团队名称" align="center" prop="name" />
        <el-table-column label="指导单位" align="center" prop="college" />
        <el-table-column label="分数" align="center" prop="onlineScore1" />
        <el-table-column label="状态" align="center" prop="onlineStatus1">
          <!-- 0是待评审 1 是评审通过 2是拒绝 -->
          <template slot-scope="scope">
            {{
              scope.row.onlineStatus1 == 0
                ? '待审核'
                : scope.row.onlineStatus1 == 1
                ? '审核通过'
                : scope.row.onlineStatus1 == 2
                ? '拒绝'
                : ''
            }}
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="psSuccess">评审通过</el-button>
        <el-button type="primary" @click="psFail">评审拒绝</el-button>
      </div>
    </el-dialog>

    <el-dialog title="评分" :visible.sync="pfOpen" width="800px" append-to-body>
      <el-table style="margin-top: 10px" border :data="pfList">
        <!-- <el-table-column type="selection" width="50" align="center" /> -->
        <el-table-column label="团队名称" align="center" prop="teamName" width="300" />
        <el-table-column label="指导单位" align="center" prop="college" />
        <el-table-column label="分数" align="center" prop="onlineScore1">
          <!-- <template slot-scope="scope">
              <el-input
                :disabled="['1'].includes(scope.row.onlineStatus1)"
                size="small"
                v-model="scope.row.onlineScore1"
                placeholder="请输入分数"  
              ></el-input>
          </template> -->
          <template slot-scope="scope">
            <div
              v-show="scope.row.scoreList.length > 1"
              style="border-bottom: 1px solid #ddd"
              v-for="(val, index) in scope.row.scoreList"
              :key="index"
            >
              <div>{{ val.score + '\n' }}</div>
            </div>
            <el-input
              v-show="scope.row.scoreList.length <= 1"
              :disabled="['1'].includes(scope.row.scoreList[0].status)"
              size="small"
              v-model="scope.row.scoreList[0].score"
              placeholder="请输入分数"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column label="状态" align="center" prop="statusName">
          <template slot-scope="scope">
            <div
              v-show="scope.row.scoreList.length > 1"
              style="border-bottom: 1px solid #ddd"
              v-for="(val, index) in scope.row.scoreList"
              :key="index"
            >
              <div>{{ val.statusName + '\n' }}</div>
            </div>
            <div
              v-show="scope.row.scoreList.length <= 1"
              v-for="(val, index) in scope.row.scoreList"
              :key="index"
            >
              <div>{{ scope.row.scoreList[0]?scope.row.scoreList[0].statusName:"未提交"}}</div>
            </div>
          </template>
          <!-- 0是待评审 1 是评审通过 2是拒绝 -->
          <!-- <template slot-scope="scope">
            {{
              scope.row.onlineStatus1 == -1
                ? '待评分'
                :scope.row.onlineStatus1 == 0
                ? '待审核'
                : scope.row.onlineStatus1 == 1
                ? '审核通过'
                : scope.row.onlineStatus1 == 2
                ? '拒绝'
                : ''
            }}
          </template> -->
        </el-table-column>
      </el-table>
      <!-- v-if="pfList && pfList[0] && ['-1', '2'].includes(pfList[0].onlineStatus1)" -->
      <div slot="footer" v-if="canCheck" class="dialog-footer">
        <el-button type="primary" @click="onlineUP">线上评分提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listTeam,
  getTeam,
  delTeam,
  addTeam,
  updateTeam,
  exportTeam,
  getHaveReviewRole,
  listCollegeAccreditationForSchoolMatch,
  psSuccess,
  SchoolMatchScoreUp,
  downloadTemplateTeam,
  listPrincipal,
  listJudge,
  downloadSchoolMatchUpload,
  listJudgesAppraisal,
} from '@/api/eqxm/team';
import { listSponsor } from "@/api/system/sponsor";
import { listOption } from '@/api/system/option';
import CommonUtils from '@/utils/CommonUtils';
import { getToken } from '@/utils/auth';

export default {
  name: 'Team',
  dicts: ['schoolmatch_2'],
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      idsPs: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 团队表格数据
      teamList: [],
      pfList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        params: {
          schoolSearch: '1',
        },
        name: null,
        college: null,
        researchtopic: null,
        isimportant: null,
        presentation: null,
        presentationdetail: null,
        transportation: null,
        accommodation: null,
        publicity: null,
        schoolMatchStatus1: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      recommendOptions: [],
      isHaveReviewRole: false,
      researchtopics: [],

      onlineStatuss: [],
      teamid: '',
      advancedPrizeOpen: false,
      advancedPrize: '',
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/eqxm/team/importData',
      },
      psOpen: false,
      pfOpen: false,
      psList: [],
      researchtopics: [],
      // 评委列表
      judgeList: [],
      judgeId: null,
      unitNameList: [],
      canCheck: false,
    };
  },
  created() {
    this.getHaveReviewRole();
    this.getDicts('teamstatus').then(response => {
      this.teamstatus = response.data;
    });
    listOption({ optionType: 1 }).then(response => {
      this.researchtopics = response.rows;
    });
    
    // this.getDicts("researchtopic").then(response => {
    //   this.researchtopics = response.data;
    // });
    listSponsor().then(response => {
      this.unitNameList = response.rows;
      console.log(response, '111');
    });
    this.getDicts('isimportant').then(response => {
      this.isimportants = response.data;
    });
    this.getList();
    this.getDicts('recommend').then(response => {
      this.recommendOptions = response.data;
    });
    this.getDicts('onlineStatus1').then(response => {
      this.onlineStatuss = response.data;
    });
  },
  methods: {
    getClockScore(row, colum) {
      var bl = row.actualClockAllCount / row.shouldClockAllCount;
      if (bl < 0.8) {
        return 0;
      } else if (0.8 <= bl && bl < 0.9) {
        return 6;
      } else if (0.9 <= bl && bl < 1) {
        return 8;
      } else if (1 == bl) {
        return 10;
      } else {
        return 0;
      }
    },
    getAllScore(row, colum) {
      var dk = 0;
      var xs = 0;
      var xx = 0;
      var bl = row.actualClockAllCount / row.shouldClockAllCount;

      if (bl < 0.8) {
        dk = 0;
      } else if (0.8 <= bl && bl < 0.9) {
        dk = 6;
      } else if (0.9 <= bl && bl < 1) {
        dk = 8;
      } else if (1 == bl) {
        dk = 10;
      } else {
        dk = 0;
      }

      xs = row.onlineScore1;
      xx = row.offlineScore;
      var zf = xs * 0.3 + 0.6 * xx + bl;
      //取整数了，
      return parseInt(zf);
    },

    statusFormat(row, column) {
      return this.selectDictLabel(this.teamstatus, row.status);
    },
    isimportantFormat(row, column) {
      return this.selectDictLabel(this.isimportants, row.isimportant);
    },
    researchtopicFormat(row, column) {
      return this.selectDictLabel(this.researchtopics, row.researchtopic);
    },
    recommendFormat(row, column) {
      return this.selectDictLabel(this.recommendOptions, row.recommend);
    },
    onlineStatusFormat(row, column) {
      return this.selectDictLabel(this.onlineStatuss, row.onlineStatus1);
    },

    /** 查询团队列表 */
    getList() {
      this.queryParams.schoolMatchStatus1 = '3';
      this.loading = true;
      listTeam(this.queryParams).then(response => {
        this.teamList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        delFlag: null,
        college: null,
        createBy: null,
        researchtopic: null,
        isimportant: null,
        createTime: null,
        presentation: null,
        updateBy: null,
        presentationdetail: null,
        updateTime: null,
        transportation: null,
        accommodation: null,
        publicity: null,
        schoolMatchStatus1: null,
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    handleSelectionChangePs(selection) {
      console.log(selection, 'selection');
      this.idsPs = selection.map(item => item.id);
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      //清空store的项目信息
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatchScore/teamManage', //跳转的路径
        query: { type: 0 },
      });
    },
    /** 团队信息按钮 */
    handleUpdate(row) {
      this.reset();
      let teamInfo = {
        id: row.id,
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatchScore/teamManage', //跳转的路径
        query: { type: 0 },
      });
    },
    // upload(row) {
    //   this.reset();
    //   let teamInfo = {
    //     id: row.id,
    //   };
    //   CommonUtils.setCurTeamInfo(teamInfo);
    //   const vm = this;
    //   vm.$router.push({
    //     //核心语句
    //     path: '/team/upload', //跳转的路径
    //     query: { type: 0 },
    //   });
    // },
    /** 查看团队材料按钮操作 */
    teamHandleDownload(row) {
      this.reset();
      const id = row.id || this.ids;
      downloadTemplateTeam(id).then(response => {
        if (response != undefined || response != null) {
          if (response.data.size > 0) {
            let fileName = decodeURI(response.headers.contentfile);

            let contentType = 'application/x-msdownload;';
            let blob = new Blob([response.data], {
              type: contentType + 'charset=UTF-8',
            });
            if (window.navigator.msSaveOrOpenBlob) {
              //IE10+下载
              navigator.msSaveBlob(blob, fileName);
            } else {
              // 非IE下载
              var link = document.createElement('a');
              link.href = window.URL.createObjectURL(blob);
              link.download = fileName;
              link.click();
              //释放内存
              window.URL.revokeObjectURL(link.href);
            }
          }
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTeam(this.form).then(response => {
              if (response.code == 200) {
                this.$modal.msgSuccess('修改成功');
                this.open = false;
                this.getList();
              }
            });
          } else {
            addTeam(this.form).then(response => {
              if (response.code == 200) {
                this.$modal.msgSuccess('新增成功');
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除团队编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(function () {
          return delTeam(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess('删除成功');
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      var that = this;
      this.$confirm('是否确认导出所有团队数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(function () {
          console.log(queryParams, 'queryParams');
          that.download(
            '/eqxm/team/export',
            { ...queryParams },
            `teamScore_${new Date().getTime()}.xlsx`
          );
          // return exportTeam(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    recommendTeam() {
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatch/recommendTeam', //跳转的路径
      });
    },
    judge() {
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatch/judge', //跳转的路径
      });
    },
    review() {
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatch/review', //跳转的路径
      });
    },
    collegeScore1() {
      let teamInfo = {
        id: '',
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatch/collegeScore1', //跳转的路径
      });
    },
    getHaveReviewRole() {
      getHaveReviewRole().then(response => {
        this.isHaveReviewRole = response;
      });
    },
    GetPercent(num, total) {
      num = parseFloat(num);
      total = parseFloat(total);
      if (isNaN(num) || isNaN(total)) {
        return '=';
      }
      return total <= 0 ? '0%' : Math.round((num / total) * 10000) / 100.0 + '%';
    },
    schoolMatchPrizeOpenF(row) {
      this.teamid = row.id;
      this.advancedPrize = '';
      this.advancedPrizeOpen = true;
    },
    advancedPrizeSubmitForm() {
      let advancedPrizeFrom = {};
      advancedPrizeFrom.id = this.teamid;
      advancedPrizeFrom.teamPrize1 = this.advancedPrize;
      updateTeam(advancedPrizeFrom).then(response => {
        if (response.code == 200) {
          this.$modal.msgSuccess('颁奖成功');
          this.getList();
          this.advancedPrizeOpen = false;
        }
      });
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = '导入线下评分';
      this.upload.url = process.env.VUE_APP_BASE_API + '/eqxm/team/importData';
      this.upload.open = true;
    },
    handleImportOnline() {
      this.upload.title = '导入线上评分';
      this.upload.url = process.env.VUE_APP_BASE_API + '/eqxm/team/importDataOnline';
      this.upload.open = true;
    },
    toPsOpen(){
      listJudge({ roleId: 143 }).then(response => {
        this.judgeList = response.rows;
      });
      this.psOpen = true;
    },
    handlePF() {
      this.pfOpen = true;
      var queryParams = {
        scoreType: 1,
      };
      // pageNum: 1,
      //   pageSize: 100,
      //   params: {
      //     schoolSearch: '1',
      //   },
      //   schoolMatchStatus1:'3',
      //   principalName:'judge',
      this.loading = true;
      this.canCheck = false;
      listJudgesAppraisal(queryParams).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          if(response.data[i].scoreList.length > 1){
            break;
          }else if(response.data[i].scoreList[0].status==null || response.data[i].scoreList[0].status== 0){
            this.canCheck = true;
            break;
          }
        }
        this.pfList = response.data;
        console.log(this.pfList, 'pfList');
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then(response => {
        this.download(response.msg);
      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    seeUpload(row, uploadId) {
      // debugger
      let teamInfo = {
        id: row.id,
      };
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/schoolmatchScore/seeUpload/' + uploadId, //跳转的路径
      });
    },
    // 下载
    openUrl(id) {
      // downloadSchoolMatchUpload({ id: id }).then(response => {
      //   this.download(response.msg);
      // });
      // console.log(fileName, 'fileName');
      // // window.open(fileName);
      // this.download(
      //   '/eqxm/team/SchoolMatchUpload/download',
      //   { id: id },
      //   `SchoolMatch_${new Date().getTime()}`
      // );
      window.open(process.env.VUE_APP_BASE_API +`/eqxm/team/SchoolMatchUpload/download?id=${id}&schoolMatchType=1`);
    },
    collegeAccreditation(createBy) {
      listCollegeAccreditationForSchoolMatch({ createBy: createBy, scoreType: 1 }).then(
        response => {
          this.psList = response.rows;
          // for (let i = 0; i < response.rows.length; i++) {
          //   let info = response.rows[i]
          this.idsPs = response.rows.map(item => item.id);
          // }
          console.log(this.idsPs, 'idsPs');
          this.loading = false;
          // this.psOpen = true;
        }
      );
    },
    psFail() {
      // this.$modal.msgSuccess('评审成功');
      // this.psOpen = false;
      if (this.idsPs.length > 0) {
        psSuccess(this.idsPs, '2',1).then(response => {
          if (response.code == 200) {
            this.$modal.msgSuccess('评审成功');
            this.collegeAccreditation(this.judgeId);
            this.getList();
            this.psOpen = false;
          }
        });
      } else {
        this.$modal.msgError('无审核数据');
      }
    },
    psSuccess() {
      if (this.idsPs.length > 0) {
        psSuccess(this.idsPs, '1',1).then(response => {
          if (response.code == 200) {
            this.$modal.msgSuccess('评审成功');
            this.collegeAccreditation(this.judgeId);
            this.getList();
            this.psOpen = false;
          }
        });
      } else {
        this.$modal.msgError('无审核数据');
      }
    },
    onlineUP() {
      var jsonData = [];
      // for (let i = 0; i < this.pfList.length; i++) {
      //   jsonData[i].id = this.pfList[i].id;
      //   jsonData[i].onlineScore1 = this.pfList[i].onlineScore1;
      // }
      this.pfList.forEach(item => {
        jsonData.push({
          id: item.teamid,
          onlineScore1: item.scoreList[0].score,
        });
        // onlineScore1: item.onlineScore1,
      });
      jsonData = JSON.stringify(jsonData);
      SchoolMatchScoreUp(jsonData, 1).then(response => {
        if (response.code == 200) {
          this.$modal.msgSuccess('评分成功');
          this.getList();
          this.pfOpen = false;
        }
      });
    },
  },
};
</script>
